﻿using H.Configs;
using H.Daos;
using H.Eyes;
using H.Eyes.Remotings;
using H.Hands;
using H.Logs;
using H.Nets;
using H.QuickDoes;
using H.Remotings;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Remoting.Channels;
using System.Text;

namespace H
{
    /// <summary>
    /// H服务
    /// </summary>
    public static class HService
    {
        /// <summary>
        /// 默认的网络模块工厂
        /// </summary>
        public static readonly Lazy<INetFactory> DefaultNetFactory = new Lazy<INetFactory>(() => IPlugin.GetObject<INetFactory>("H.Net"));

        /// <summary>
        /// 默认的数据访问模块工厂
        /// </summary>
        public static readonly Lazy<IDaoFactory> DefaultDaoFactory = new Lazy<IDaoFactory>(() => IPlugin.GetObject<IDaoFactory>("H.Dao.SQLite"));

        /// <summary>
        /// 默认的配置文件模块工厂
        /// </summary>
        public static readonly Lazy<IConfigFactory> DefaultConfigFactory = new Lazy<IConfigFactory>(() => IPlugin.GetObject<IConfigFactory>("H.Config"));

        /// <summary>
        /// 默认的日志收集器工厂
        /// </summary>
        public static readonly Lazy<ILoggerFactory> DefaultLoggerFactory = new Lazy<ILoggerFactory>(() => IPlugin.GetObject<ILoggerFactory>("H.Logger"));

        /// <summary>
        /// 默认的快速操作工厂
        /// </summary>
        public static readonly Lazy<IQuickDoFactory> DefaultQuickDoFactory = new Lazy<IQuickDoFactory>(() => IPlugin.GetObject<IQuickDoFactory>("H.QuickDo"));

        /// <summary>
        /// 默认的图像识别操作工厂
        /// </summary>
        public static readonly Lazy<IEyeFactory> DefaultEyeFactory = new Lazy<IEyeFactory>(() => IPlugin.GetObject<IEyeFactory>("H.DML"));

        /// <summary>
        /// 默认的键鼠操作工厂
        /// </summary>
        public static readonly Lazy<IHandFactory> DefaultHandFactory = new Lazy<IHandFactory>(() => IPlugin.GetObject<IHandFactory>("H.KML"));

        /// <summary>
        /// 默认的远程工厂
        /// </summary>
        public static readonly Lazy<IRemotingFactory> DefaultRemotingFactory = new Lazy<IRemotingFactory>(() => IPlugin.GetObject<IRemotingFactory>("H.Driver.Client"));


        /// <summary>
        /// 根据一个相对于HRuntime的相对路径,获取全路径
        /// </summary>
        /// <param name="relativePath">相对于HRuntime相对路径</param>
        /// <returns>返回绝对路径</returns>
        public static string GetEnvPath(string relativePath)
        {
            return Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.GetData("HRT.APPBASE") as string ?? AppDomain.CurrentDomain.BaseDirectory, relativePath));
        }

    }
}
